#!/usr/bin/env python3
"""
启动脚本，用于启动CTF Judge Agent API服务器
"""

import os
import sys
import uvicorn
from pathlib import Path

# 添加项目根目录到Python路径
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))

def main():
    """启动服务器"""
    print("🚀 Starting CTF Judge Agent API Server...")
    print(f"📁 Project root: {project_root}")
    print(f"🌐 Server will be available at: http://localhost:8000")
    print(f"📖 API documentation: http://localhost:8000/docs")
    print(f"🔧 Health check: http://localhost:8000/health")
    print()
    print("Available endpoints:")
    print("  GET  /evaluate           - 评估用户或题目性能")
    print("  POST /evaluate_stream    - 流式评估用户或题目性能")
    print("  GET  /tools              - 获取可用工具列表")
    print("  GET  /health             - 健康检查")
    print()
    
    try:
        # 切换到Server目录
        os.chdir(Path(__file__).parent)
        
        uvicorn.run(
            "AgentAPI:app",
            host="0.0.0.0",
            port=8000,
            reload=True,
            log_level="info",
            access_log=True
        )
    except KeyboardInterrupt:
        print("\n🛑 Server stopped by user")
    except Exception as e:
        print(f"❌ Server error: {e}")
        sys.exit(1)

if __name__ == "__main__":
    main()
